package com.singzi.leetcode.N1100;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

public class T1078 {
}
class Solution1078 {
    public String[] findOcurrences(String text, String first, String second) {
        List<String> list = new ArrayList<>();
        List<String> resultList = new ArrayList<>();
        int length = text.length();
        int index = 0;
        for (int i = 0; i < length; i++) {
            if(text.charAt(i) == ' '){
                String temp = text.substring(index, i);
                index = i+1;
                list.add(temp);
            }
        }
        String temp = text.substring(index, length);
        list.add(temp);
        for (int i = 0; i < list.size()-2; i++) {
            if(Objects.equals(list.get(i), first) && Objects.equals(list.get(i + 1), second)){
                resultList.add(list.get(i+2));

            }
        }
        length = resultList.size();
        String []result = new String[length];
        for (int i = 0; i < length; i++) {
            result[i] = resultList.get(i);
        }

        return result;
    }
}